<template>
  <view class="paymentsuccess">
    <view class="top">
      <uni-icons class="back" type="back" size="30" @click="back()"></uni-icons>
      <view>支付成功</view>
    </view>
    <view class="success">
      <image src="https://cdn3.axureshop.com/demo/2116044/images/%E6%94%AF%E4%BB%98%E6%88%90%E5%8A%9F/u1737.png"
        mode=""></image>
      <view>支付成功</view>
      <view>订单金额：￥{{paymoney}}</view>
    </view>
    <view class="btn">
      <button @click="look">查看订单</button>
    </view>
  </view>
</template>

<script>
  import http from '@/utils/http.js'
  export default {
    data() {
      return {
        balance: '0',
        price: '0',
        userid: '1',
        paymoney: '0',
        status: '制作中',
        orderid: '0',
        list: [],
        seeList: {},
        active: '堂食'
      }
    },
    methods: {
      back() {
        let pages = getCurrentPages();
        console.log(pages);
        let backPages = pages.length - 1;
        uni.navigateBack({
          delta: backPages,
        })
      },
      look() {
        http({
          url: `/list`,
          params: {
            active: this.active,
            userid: this.userid
          },
          success: (res) => {
            if (res.data.msg == '获取成功') {
              this.list = res.data.listData;
              // console.log(this.list[1].id);
              for (let i in this.list) {
                if (this.list[i].id == this.orderid) {
                  this.seeList = this.list[i]
                  // console.log(this.seeList);
                  uni.navigateTo({
                    url: '/pages/listDetail/listDetail?item=' + JSON.stringify(this.seeList),
                    // success: res => {},
                    // fail: () => {},
                    // complete: () => {}
                  });
                  break;
                }
              }
            } else {
              uni.showToast({
                title: res.data.msg,
                icon: 'error'
              })
            }
          }
        })

      }
    },
    onShow() {
      this.balance = uni.getStorageSync('balance');
      console.log(this.balance);
      this.balance = this.balance - this.price;
      http({
        url: '/editbalance',
        method: 'post',
        data: {
          balance: this.balance,
          userid: this.userid
        },
        success: (res) => {
          console.log(res);
        }
      });
      http({
        url: '/editstat',
        method: 'post',
        data: {
          status: this.status,
          orderid: this.orderid,
        },
        success: (res) => {
          console.log(res);
        }
      });
    },
    onLoad: function(option) {
      console.log(option.paymoney);
      this.paymoney = option.paymoney;
      this.price = option.paymoney;
      let tempVal = Number(this.paymoney).toFixed(2);
      let realVal = tempVal.substring(0, tempVal.length - 1);
      this.paymoney = realVal;
      this.orderid = uni.getStorageSync('orderid');
      console.log(this.orderid);
    },
  }
</script>

<style scoped>
  .top {
    padding-top: 60rpx;
    padding-bottom: 20rpx;
    display: flex;
    justify-content: center;
    font-size: 30rpx;
    background-color: #ffffff;
    border-bottom: #F2F2F2 solid 1rpx;
  }

  .top>.back {
    position: absolute;
    left: 0;
    zoom: 0.8;
  }

  .success {
    width: 100%;
    height: 260rpx;
    text-align: center;
    margin-top: 160rpx;
  }

  .success image {
    width: 100rpx;
    height: 100rpx;
  }

  .success view:nth-child(2) {
    font-size: 30rpx;
    margin-top: 10rpx;
  }

  .success view:nth-child(3) {
    font-size: 25rpx;
    margin-top: 10rpx;
    color: #666666;
  }

  .btn {
    height: 130rpx;
    width: 100%;
    background-color: #ffffff;
  }

  .btn button {
    width: 650rpx;
    background-color: #ffffff;
    color: #f77214;
    border: 1rpx solid #f77214;
    font-size: 30rpx;
    margin-top: 20rpx;
    border-radius: 50rpx;
  }

  .btn button image {
    width: 25rpx;
    height: 25rpx;
    margin-right: 10rpx;
  }
</style>
